﻿

Imports System.Data
Imports VSModel
Imports Cls_Common
Partial Class FrontEnd_Control_WhatCookToDay_Menu
    Inherits System.Web.UI.UserControl
    Public curStoreURL As String = ""

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            LoadMenu()
        End If
    End Sub
    Protected Sub LoadMenu()
        Dim lstNode As New DataSet
        lstNode.ReadXml(MapPath("../../../xml/AmThuc.xml"))
        With rptMenu
            .DataSource = lstNode.Tables("Node")
            .DataBind()
        End With

    End Sub

    Protected Sub rptMenu_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptMenu.ItemDataBound
        Dim hplTitle As HyperLink = CType(e.Item.FindControl("hplTitle"), HyperLink)
        hplTitle.NavigateUrl = MainDomain & e.Item.DataItem("URL")
        Dim lblTitle As Label = CType(e.Item.FindControl("lblTitle"), Label)
        lblTitle.Text = e.Item.DataItem("Title")
        Dim ltrSubMenu As Literal = CType(e.Item.FindControl("ltrSubMenu"), Literal)
        If e.Item.DataItem("URL").ToString = "thuc-don-hang-ngay-139.html" Then
            ltrSubMenu.Text = GenSubMenu()
        End If
        'end bind menu
    End Sub
    Protected Function GenSubMenu() As String
        Dim str As String = "<div class='sub'><ul>"
        Using Data As New VSEntities

            'Load loai cong thuc nau an
            Dim k = (From l In Data.FormulaTypes Select l.Title, l.Id, l.QueryString).ToList
            For Each a In k
                str = str & "<li><a href='" & MainDomain & a.QueryString & "-139-" & a.Id & "f.html'>" & a.Title & "<a></li>"
            Next

        End Using

        Return str & "</ul><div class='btm-bg'></div></div>"
    End Function
End Class
